package com.xiong.jsonutils;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;

import java.util.List;

/**
 * @author Xiongx
 * @version 1.0
 * @date 2021/8/4 11:04
 * @since JDK 1.8
 */
public class JsonUtils {

    public static <T> T objectForamtDate(T t){
        String var=JSONObject.toJSONString(t,SerializerFeature.WriteDateUseDateFormat);
        Class<T> cls=(Class<T>) t.getClass();
        return JSONObject.parseObject(var,cls);
    }

    public static <T> T objectForamtDate(T t,String formart){
       String var=JSONObject.toJSONStringWithDateFormat(t,formart,SerializerFeature.IgnoreNonFieldGetter);
       Class<T> cls=(Class<T>) t.getClass();
       return JSONObject.parseObject(var,cls);
    }

    public static <T> List<T> arrayFormartDate(List<T> tList,String formart,Class<T> cls){
        String var=JSONArray.toJSONStringWithDateFormat(tList,formart,SerializerFeature.IgnoreNonFieldGetter);
        return JSONArray.parseArray(var,cls);
    }




}
